<?php
class IndexController extends Controller {
	
	function actionIndex() {
		echo APP_URL;
		//exit ( '<h2>It Works</h2>' );
		$this->display ( 'index.htm' );
	}
	
	private function actionNews() {
		echo "private method!";
	}
	
	public function actionCache() {
		$cache = Mid::cache ( 'file' );
		$cache->set ( '123456', 'fuck' );
		echo $cache->get ( '123456' );
	}
	
	public function actionMail() {
		$mailer = Mid::helper ( 'mailer' );
		//$mailer->login ( 'smtp', 'corrie管理员<corrie@sina.com>', 'smtp.sina.com', 'corrie', '' );
		//echo $mailer->quicksend ( 'hfcorriez<hfcorriez@gmail.com>', '恭喜收到测试邮件！', '收到这封邮件，证明你完成了helper mailer的测试！' );
		$mailer->singleSend ( array ('hfcorriez@gmail.com', 'corriezhao@pplive.com', 'hfcorriez@gmail.com', 'corriezhao@pplive.com', 'hfcorriez@gmail.com', 'hfcorriez@gmail.com', 'corriezhao@pplive.com', 'hfcorriez@gmail.com', 'hfcorriez@gmail.com', 'corriezhao@pplive.com', 'hfcorriez@gmail.com' ), 'Group send!', 'You are fine!' );
	}
	
	public function actionDb() {
		$model = parent::Model ( 'index.index' );
		$this->addData ( $model->fetch () );
		$this->display ( 'index.htm' );
	}
	
	function actionGuid() {
		echo Mid::helper ( 'guid' )->toString ();
		exit ();
	}
	
	public function actionBenchmark() {
		$debuger = Mid::Helper ( "debuger" );
		$starttime = $debuger->getMicroTime ();
		Mid::load ( "i:class:benchmark" );
		$isave = new InstanceSave ( );
		for($i = 0; $i < 100000; $i ++) {
			$isave->set ( 'key_' . $i, 'benchmark test!' );
			//$isave->get ( 'key_' . $i );
		}
		echo "对象存取时间：" . ($debuger->getMicroTime () - $starttime) . '<br />';
		$starttime = $debuger->getMicroTime ();
		for($i = 0; $i < 100000; $i ++) {
			StaticSave::set ( 'key_' . $i, 'benchmark test!' );
			//StaticSave::get ( 'key_' . $i );
		}
		echo "静态类存取时间：" . ($debuger->getMicroTime () - $starttime) . '<br />';
	}
	
	public function actionTest() {
		$str = 'ktv-test.html';
		$pattern = '/([a-z]+)\-([a-z]+)\.html/';
		preg_match ( $pattern, $str, $match );
		print_r ( $match );
	}
	
	public function actionJson() {
		$arr = array ('attr' => array ('name' => 'form1', 'id' => 'form1' ), 'lines' => array (array ('name' => 'username', 'id' => 'username' ), 'hahaha' ) );
		//$str = '{"name":"wocao","abc123":"abc"}';
		//print_r(json_decode($str));
		echo json_encode ( $arr );
	}
	
	public function actionYaml() {
		Mid::loadLib ( 'spyc/spyc' );
		$Data = Spyc::YAMLLoad ( Mid::path ( 'd/test.form', false ) );
		print_r ( $Data );
	}
	
	public function actionImage() {
		$image = Mid::helper ( 'image' );
		/*$array = array(
			'font:' . APP_ROOT . 'MSYH.TTF;size:20;color:#ffffff' => '你怎么弄的？'
		);*/
		$array [3] = APP_ROOT . 'pplive.png';
		//$path = $image->file(array(APP_ROOT.'1.jpg', APP_ROOT . '2.jpg'))->to(IMAGE_ORG_DIR)->thumb()->getPath();
		

		$path = $image->file ( array (APP_ROOT . '1.jpg', APP_ROOT . '2.jpg' ) )->to ( IMAGE_ORG_DIR )->thumb ()->getPath ();
		print_r ( $path );
	}
	
	public function actionUpload() {
		$up = Mid::helper ( 'upload' );
		//var_dump ( $up->upload ( $_FILES ['files'], APP_ROOT ) );
		var_dump ( $up->file ( $_FILES ['files'] )->to ( APP_ROOT )->sub ( 'abc/eot' )->upload ()->getPath () );
		print_r ( $up->getError () );
	}
	
	function __destruct() {
		echo Mid::Runtime ();
	}
}
?>